#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cJSON.h"
int main()
{
	cJSON *pTmpJson, *pTmpJson_, *pTmpJson__;
	char *pStrJson;
	char tmpString[1024] = {0};
	/*	5. Get VIP					*/
	{
		//
		memset(tmpString, 0, sizeof(tmpString));
		//memcpy(tmpString, pTmpJson->string, min(sizeof(tmpString), strlen(pTmpJson->string)));
		memcpy(tmpString, "eth13,192.169.210.10,255.255.255.0;eth23,192.169.210.11,255.255.255.0;eth1,192.169.210.10,255.255.255.0;eth2,192.169.210.11,255.255.255.0;", sizeof(tmpString));
	}
	char *pch1, *pch2, *pch3;
	if ((pTmpJson_ = cJSON_CreateArray()) == NULL) {
		printf("cJSON_CreateArray failed!\n");
	}
	int i = 0;
	pch1 = tmpString;
	do {
		i++;
		printf("%d\n", i);
		pch2 = pch1;
		pch1 = strchr(pch1, ';');
		if (pch1 == NULL) {
			printf("%d\n", __LINE__);
			break;
		}
		*pch1 = '\0';
		if ((pTmpJson = cJSON_CreateObject()) == NULL) {
			cJSON_Delete(pTmpJson_);
			return -1;
		}
		pch3 = strchr(pch2, ',');
		if (!pch3) {
			printf("%d\n", __LINE__);
			cJSON_Delete(pTmpJson);
			break;
		}
		*pch3 = '\0';
		cJSON_AddStringToObject(pTmpJson, "deviceName", pch2);
		pch2 = pch3 + 1;
		pch3 = strchr(pch2, ',');
		if (!pch3) {
			printf("%d\n", __LINE__);
			cJSON_Delete(pTmpJson);
			break;
		}
		*pch3 = '\0';
		cJSON_AddStringToObject(pTmpJson, "IPAddress", pch2);
		pch2 = pch3 + 1;
		cJSON_AddStringToObject(pTmpJson, "netMask", pch2);

		cJSON_AddItemToArray(pTmpJson_, pTmpJson);
	} while(*(++pch1));
	
	
	/*	6. Get succeed!				*/
	pStrJson = cJSON_PrintUnformatted(pTmpJson_);
	printf("%s\n", pStrJson);
}
